package com.liangzhong.model.match
{
	import com.liangzhong.model.AppData;
	
	import flash.utils.ByteArray;

	/**
	 * 比赛开始
	 * @author lxh
	 * 
	 */	
	public class GameStart
	{
		public var matchId 			:int;//比赛ID
		public var isHome			:Boolean ;//是否主客场
		public var bankerUserId 	:int;//主队用户ID
		public var playerUserId		:int;//客队用户ID
		/**
		 *A 对球员id 包括替补 
		 */		
		public var aPlayerIds	:Array;
		/**
		 *B 对球员id 包括替补 
		 */		
		public var bPlayerIds	:Array;
		
		public function GameStart()
		{
		}
		/**
		 *获取自己ids 
		 * @return 
		 * 
		 */		
		public function get selfIds():Array
		{
			if(isHome)
			{
				return aPlayerIds.slice(0,11);
			}
			else
			{
				return bPlayerIds.slice(0,11);
			}
		}
		/**
		 * @param data
		 * 
		 */		
		public function readData(data : ByteArray):void
		{
			matchId 		= data.readUnsignedInt();
			bankerUserId 	= data.readUnsignedInt();
			playerUserId 	= data.readUnsignedInt();
			var ids :Array = [];
			var i :int = 0;
			var id :int;
			while(i < 22)
			{
				id = data.readUnsignedInt();
				if(id > 0)
				{
					ids.push(id);
				}
				i ++ ;
			}
			aPlayerIds = ids;
			//AppData.getInstance().matchDataManager.aPlayerIds = aPlayerIds;
			i = 0;
			ids = [];
			while(i < 22)
			{
				id = data.readUnsignedInt();
				if(id > 0)
				{
					ids.push(id);
				}
				i ++ ;
			}
			bPlayerIds = ids;
			//AppData.getInstance().matchDataManager.bPlayerIds = bPlayerIds;
			//trace(aPlayerIds,bPlayerIds);
		}
		/**
		 *解析记录中数据
		 * @param obj
		 */		
		public function parseHistoryData(obj :Object):void
		{
			for(var str:String in obj)
			{
				if(this.hasOwnProperty(str))
				{
					this[str] = obj[str];
				}
			}
			//AppData.getInstance().matchDataManager.aPlayerIds = aPlayerIds;
			//AppData.getInstance().matchDataManager.bPlayerIds = bPlayerIds;
		}
		public function toString():String
		{
			return "{matchId:" + matchId + ",bankerUserId:" + bankerUserId + ",playerUserId:" + playerUserId +"}"
		}
	}
}